package com.model.common.utils.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.model.common.R;


/**
 * Created by xch on 2021/12/23.
 * 封装的缓冲加载页面
 */
public class LoadingView extends FrameLayout {
    /**
     * 正在加载
     */
    private ProgressBar mProgressView;
    /**
     * 加载状态的提示标题
     */
    private TextView mTvLoadingHint;

    public LoadingView(Context context) {
        super(context);
        init();
    }

    public LoadingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View loadingPager = View.inflate(getContext(), R.layout.loading_view, this);
        mProgressView = loadingPager.findViewById(R.id.progressView);
        mTvLoadingHint = loadingPager.findViewById(R.id.tv_loading_message);
    }

    /**
     * 设置加载界面
     */
    public void setLoadingState(String text) {
        mProgressView.setVisibility(VISIBLE);
        if (null == text || "".equals(text)) {
            mTvLoadingHint.setText("正在加载...");
        } else {
            mTvLoadingHint.setText(text);
        }
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // 消费touch事件
        return true;
    }
}
